/**
 * Copyright (c) 2002-2011 旭鸣信息
 * All rights reserved. 
 * File：AbsDefaultDao.java
 * History:
 *       2012-1-13: Initially created, tangkf.
 */
package com.xteam.purview.service;

import java.util.List;

import com.xteam.db.BaseDao;
import com.xteam.db.IBaseDao;
import com.xteam.db.page.Page;
import com.xteam.db.page.PageObjectSet;

/**
 * 基本业务接口抽象实现
 * @author tangkf ---2012-1-13
 */
public abstract class AbsFace<T> implements IFace<T> {

	public static IBaseDao	dao	= BaseDao.getInstance();

	/**
	 * @see com.xteam.purview.dao.IDao#save(java.lang.Object)
	 */
	public int save(T obj) {
		int r = 0;
		try {
			r = dao.saveObject(obj);
		} catch (Exception e) {
			r = 1;
			e.printStackTrace();
		}
		return r;
	}

	/**
	 * @see com.xteam.purview.dao.IDao#update(java.lang.Object)
	 */
	public int update(T obj) {
		int r = 0;
		try {
			r = dao.updateObject(obj);
		} catch (Exception e) {
			r = 1;
			e.printStackTrace();
		}
		return r;
	}

	/**
	 * @see com.xteam.purview.dao.IDao#del(java.lang.Object)
	 */
	public int del(T obj) {
		int r = 0;
		try {
			r = dao.delete(obj);
		} catch (Exception e) {
			r = 1;
			e.printStackTrace();
		}
		return r;
	}

	/**
	 * @see com.xteam.purview.dao.IDao#delBatch(java.lang.String[])
	 */
	public int delBatch(Class<T> clazz, String idName, String[] ids) {
		int r = 0;
		try {
			r = dao.deleteBathById(clazz, idName, ids);
		} catch (Exception e) {
			r = 1;
			e.printStackTrace();
		}
		return r;
	}

	/**
	 * 根据ID 返回单个对象
	 * @author tangkf  ---2012-2-8
	 * @param clazz
	 * @param idValue
	 * @return
	 */
	public T getObject(Class<T> clazz, String idValue) {
		try {
			return dao.getObject(clazz, idValue);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	/**
	 * @see com.xteam.purview.dao.IDao#query()
	 */
	public PageObjectSet<T> query(Class<T> clazz, Page page) {
		PageObjectSet<T> pos = null;
		try {
			pos = dao.query(clazz, page);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return pos;
	}

	/**
	 * @see com.xteam.purview.dao.IDao#queryAll()
	 */
	public List<T> queryAll(Class<T> clazz) {
		List<T> list = null;
		try {
			list = dao.queryAll(clazz);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return list;
	}
}